import { makeAutoObservable } from 'mobx'
class TaskStore {
  list = [
    {
      id: 1,
      name: '学习react',
      isDone: true,
    },
    {
      id: 2,
      name: '搞定mobx',
      isDone: true,
    },
  ]
  constructor() {
    makeAutoObservable(this)
  }

  singleCheck(id, isDone) {
    const item = this.list.find((item) => item.id === id)
    item.isDone = isDone
  }

  allCheck(checked) {
    return this.list.forEach((item) => (item.isDone = checked))
  }
  get isAll() {
    return this.list.every((item) => item.isDone)
  }

  delTask = (id) => {
    this.list= this.list.filter(item => item.id !== id)
  }

  addTask = (task) => {
    this.list.push(task)
  }
}
export default TaskStore
